/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.evangelion.core.daoImpl;

import com.evangelion.core.bean.Declaracion;
import com.evangelion.core.dao.DeclaracionDao;
import java.util.List;
import javax.persistence.Query;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Kellycasma
 */
@Component
@Transactional
public class DeclaracionDaoImpl extends AbstractDAO implements DeclaracionDao {

    @Override
    public List<Declaracion> listDeclaraciones(String tipo) {
        Query q = em.createQuery("SELECT a from Declaracion a WHERE a.tipo=:tipo");
        q.setParameter("tipo", "Facturacion");
        return q.getResultList();
    }

    @Override
    public Declaracion findDeclaracionByannoTrim(int anno, int trimestre) {
        Query q = em.createQuery("SELECT a from Declaracion a WHERE a.anno=:anno and a.trimestre=:trimestre AND a.tipo=:tipo");
        q.setParameter("anno", anno);
        q.setParameter("trimestre", trimestre);
        q.setParameter("tipo", "Facturacion");
        try {
            return (Declaracion) q.getSingleResult();
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    public void save(Declaracion declaracion) {
        super.save(declaracion);
    }
}
